package zoo_management_system;

import zoo_management_system.animal.Animal;
import zoo_management_system.people.ZooVisitor;
import zoo_management_system.zooInterface.Display;
import zoo_management_system.zooInterface.ZooAnimaItem;
import zoo_management_system.zooInterface.ZooVistorItem;

import java.util.List;
import java.util.ArrayList;

public class Zoo implements ZooAnimaItem, Display, ZooVistorItem {

    private String zoo_name;

    //动物园园长(只有一个)
    private String zoo_director;

    //来动物园的游客(复数个)
    private List<ZooVisitor> visitorList;

    private List<Animal> animalList;

    public Zoo() {
        this.animalList = new ArrayList<Animal>();
        this.visitorList=new ArrayList<ZooVisitor>();
        this.zoo_director=null;
    }


    public String getZoo_name() {
        return zoo_name;
    }

    public void setZoo_name(String zoo_name) {
        this.zoo_name = zoo_name;
    }

    public String getZoo_director() {
        return zoo_director;
    }

    public void setZoo_director(String zoo_director) {
        this.zoo_director = zoo_director;
    }

    public List<Animal> getAnimalList() {
        return animalList;
    }

    public void setAnimalList(List<Animal> animalList) {
        this.animalList = animalList;
    }

    @Override
    public boolean add_ainimal(Animal a) {
        return this.animalList.add(a);
    }

    @Override
    public boolean delete_ainimal(Animal a) {
        return this.animalList.remove(a);
    }

    @Override
    public boolean display_ainimal(Animal a) {
        return false;
    }

    @Override
    public boolean update_ainimal(Animal old_a, Animal new_a) {
        boolean successed_removed = this.animalList.remove(old_a);
        boolean successed_added = this.animalList.add(new_a);
        return (successed_removed && successed_added);
    }

    @Override
    public Animal find_by_animal_name(String name) {
        Animal find_animal = null;
        //用foreach循环遍历
        for( Animal a : this.animalList){
            if (a.getName().equals(name)) {
                find_animal = a;
            }
        }
        return find_animal;
    }

    @Override
    public String display_all_animals() {
        String display_message = "";
        for (Animal a : this.animalList) {
            display_message=display_message+"动物名："+a.getName()+"； 年龄："+a.getAge()+"\n";
        }
        return display_message;
    }

    @Override
    public String display_all_vistors() {
        String display_message = "";
        for (ZooVisitor z: this.visitorList) {
            display_message=display_message+"游客名："+z.getName()+"； 年龄："+z.getAge()+"\n";
        }
        return display_message;
    }

    //下面是对游客的增删查改，逻辑同动物

    @Override
    public boolean add_vistor(ZooVisitor z) {
        return this.visitorList.add(z);
    }

    @Override
    public boolean delete_vistor(ZooVisitor z) {
        return this.visitorList.remove(z);
    }

    @Override
    public boolean display_vistor(ZooVisitor z) {
        return false;
    }

    @Override
    public boolean update_vistor(ZooVisitor old_z, ZooVisitor new_z) {
        boolean successed_removed = this.visitorList.remove(old_z);
        boolean successed_added = this.visitorList.add(new_z);
        return (successed_removed && successed_added);
    }

    @Override
    public ZooVisitor find_by_vistor_name(String name) {
        ZooVisitor find_vistor = null;
        //用foreach循环遍历
        for( ZooVisitor z : this.visitorList){
            if (z.getName().equals(name)) {
                find_vistor = z;
            }
        }
        return find_vistor;
    }
}
